YouTube Video Transcriber
工作流概述
这是一个包含14个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "Iz8TMdlc6JhaKkd9",
"meta": {
"instanceId": "dacfda6d2e1dbefe99a005845405509e9929b16710017f4bd5d2bf758941295c",
"templateCredsSetupCompleted": true
},
"name": "YouTube Video Transcriber",
"tags": [],
"nodes": [
{
"id": "a4e2f554-ebae-41df-912a-0d1081fa1736",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-100,
-60
],
"webhookId": "70129cbe-1a05-495f-bd92-18d36c1bc260",
"parameters": {
"public": true,
"options": {
"title": "Youtube Video Transcriber 🚀",
"subtitle": "Have a great transcription! 📖",
"inputPlaceholder": "Insert a URL of a YouTube video. 💻"
},
"initialMessages": "Give me a URL of a video from YouTube to start! 👍"
},
"typeVersion": 1.1
},
{
"id": "34b2b12e-0eb5-4f59-bd30-e7b595d06b8c",
"name": "Code",
"type": "n8n-nodes-base.code",
"position": [
280,
-60
],
"parameters": {
"language": "python",
"pythonCode": "import re
def youtube_video_url_validatior(video_url) -> str:
try:
if not video_url:
return {\"text\": 'URL from the video is required.', \"is_valid\": False}
video_url: str = re.sub(r\"\s{2,}\", \" \", video_url.strip())
if not video_url:
return {\"text\": 'URL from the video is required.', \"is_valid\": False}
if len(video_url) < 25:
return {\"text\": 'URL is too short to be a valid YouTube URL.', \"is_valid\": False}
# if not re.match(r'^[A-Za-z0-9:/._?&=-]+$', video_url):
# return {\"text\": 'URL contains invalid characters.', \"is_valid\": False}
is_valid: bool = False
for pattern in [
r'^https?://(?:www\.)?youtube\.com/watch\?v=[\w-]{11}',
r'^https?://youtu\.be/[\w-]{11}',
r'^https?://(?:www\.)?youtube\.com/embed/[\w-]{11}',
r'^https?://(?:www\.)?youtube\.com/v/[\w-]{11}',
]:
if re.match(pattern, video_url):
is_valid = True
break
if not is_valid:
return {\"text\": 'Invalid YouTube URL format.', \"is_valid\": False}
video_url_id: str | None = re.search(r'(?:v=|youtu\.be/|embed/|v/)([\w-]{11})', video_url).group(1)
if not video_url_id or not re.match(r'^[\w-]{11}$', video_url_id):
return {\"text\": 'Invalid YouTube video ID.', \"is_valid\": False}
return {\"text\": video_url, \"is_valid\": True}
except Exception as ex:
raise ex
return youtube_video_url_validatior(_input.first().json.chatInput)"
},
"typeVersion": 2
},
{
"id": "712cbf28-df12-44fc-b54a-bc21e13e55e7",
"name": "If",
"type": "n8n-nodes-base.if",
"position": [
600,
-240
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "b8927a53-2755-4364-84b1-5340c5c31af5",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.is_valid }}",
"rightValue": ""
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "be9e1903-25bc-4f1b-8793-5e657205dd5d",
"name": "Respond to Webhook - Chat Message",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
600,
60
],
"parameters": {
"options": {},
"respondWith": "text",
"responseBody": "={{ $json.text }}"
},
"retryOnFail": true,
"typeVersion": 1.1
},
{
"id": "98bc7747-e688-4683-8686-ca44023f8648",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-200,
-240
],
"parameters": {
"color": 5,
"width": 300,
"height": 420,
"content": "## Entry Point
The workflow entry point is the node chat message."
},
"typeVersion": 1
},
{
"id": "7ca94ab6-7306-4b04-8b34-eb9e0937d681",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
180,
-240
],
"parameters": {
"color": 3,
"width": 300,
"height": 420,
"content": "## Validation - URL
This node ensures that only a valid youtube video url goes forward."
},
"typeVersion": 1
},
{
"id": "c719c022-b55b-42b3-ab5f-36c0e1d62512",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1360,
-320
],
"parameters": {
"color": 4,
"width": 460,
"height": 560,
"content": "## Data Structuring
Here is the core of the workflow, where structuring is done to get the right format to answer.
**NOTE:**
1. Users implementing this template must modify the language in the OpenAI prompt to suit their desired output.
2. An OpenAI API key is essential and must be properly configured to support data structuring and processing. "
},
"typeVersion": 1
},
{
"id": "7e1fa50f-7bd3-4bed-8537-969baa4c61de",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
820,
-480
],
"parameters": {
"color": 7,
"width": 460,
"height": 900,
"content": "## Supadata
Supadata is a powerful tool that converts YouTube video URLs into structured data via a simple API. It efficiently extracts transcriptions, making it ideal for AI training, data analysis, or text-based applications.
**NOTE:**
1. Users implementing this template must change the language in the query parameter to suit their needs.
2. An API key is required and must be configured for the workflow to function properly."
},
"typeVersion": 1
},
{
"id": "35bf3191-4113-4a92-85a8-b22d3b2a4134",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-920,
-180
],
"parameters": {
"width": 640,
"height": 300,
"content": "## Description
This workflow simplifies access to YouTube video content converting into clear and concise transcriptions, ideal for users seeking practicality. It transcribes YouTube videos directly and returns the text, eliminating the need to watch the full video.
The need for this workflow arose from the demands of studying, where, amidst the fast-paced routine of daily life, reading transcribed content proved faster and more efficient for creating summaries than watching entire videos. Often, time constraints make it difficult to watch videos in full, and written text allows for quicker absorption of information. This solution provides a seamless way to access and review content from any YouTube video, regardless of the topic."
},
"typeVersion": 1
},
{
"id": "2ea0b992-231b-4f6d-9f6f-9f488d266cfb",
"name": "Edit Fields - Respond to Chat Message 2",
"type": "n8n-nodes-base.set",
"position": [
1000,
180
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "66270798-60eb-4ab8-8572-ab957474e260",
"name": "text",
"type": "string",
"value": "={{ $json.error }} - {{ $json.message }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "9846e903-015a-4111-b582-572d473fe4d3",
"name": "Edit Fields - Respond to Chat Message 3",
"type": "n8n-nodes-base.set",
"position": [
1900,
-320
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "97e0c175-8060-43da-9761-5c25d660c7ed",
"name": "text",
"type": "string",
"value": "={{ $json.message.content }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "775e067c-3518-4c64-a939-5f9b9b435b3c",
"name": "Edit Fields - Respond to Chat Message 4",
"type": "n8n-nodes-base.set",
"position": [
1900,
100
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "66270798-60eb-4ab8-8572-ab957474e260",
"name": "text",
"type": "string",
"value": "=Something went wrong with the data structuring."
}
]
}
},
"typeVersion": 3.4
},
{
"id": "91e22fcc-79b8-48d2-ba6e-bfb699ed9a07",
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueErrorOutput",
"position": [
1000,
-100
],
"parameters": {
"url": "=https://api.supadata.ai/v1/youtube/transcript?url={{ $json.text }}&text=true&lang=pt",
"options": {
"timeout": 300000
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "x-api-key",
"value": "SUPADATA_API_KEY"
}
]
}
},
"executeOnce": false,
"notesInFlow": false,
"retryOnFail": false,
"typeVersion": 4.2,
"alwaysOutputData": false
},
{
"id": "3fce199e-2e95-40a8-a78e-20a25c3f4300",
"name": "OpenAI",
"type": "@n8n/n8n-nodes-langchain.openAi",
"onError": "continueErrorOutput",
"position": [
1460,
20
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini-2024-07-18",
"cachedResultName": "GPT-4O-MINI-2024-07-18"
},
"options": {},
"messages": {
"values": [
{
"role": "system",
"content": "You are an expert in grammar corrections and textual structuring.
Correct the classification of the provided text, adding commas, periods, question marks and other symbols necessary for natural and consistent reading. Do not change any words, just adjust the punctuation according to the grammatical rules and context.
Organize your content using markdown, structuring it with titles, subtitles, lists or other protected elements to clearly highlight the topics and information captured. Leave it in Portuguese and remember to always maintain the original formatting.
Textual organization should always be a priority according to the content of the text, as well as the appropriate title, which must make sense."
},
{
"content": "={{ $json.content }}"
}
]
}
},
"credentials": {
"openAiApi": {
"id": "GpAe9wonPZjokqpc",
"name": "OpenAi account"
}
},
"retryOnFail": true,
"typeVersion": 1.8
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "d2f6a7fb-f3e1-462f-8627-7f67cc7bfa5b",
"connections": {
"If": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond to Webhook - Chat Message",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"OpenAI": {
"main": [
[
{
"node": "Edit Fields - Respond to Chat Message 3",
"type": "main",
"index": 0
}
],
[
{
"node": "Edit Fields - Respond to Chat Message 4",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "OpenAI",
"type": "main",
"index": 0
}
],
[
{
"node": "Edit Fields - Respond to Chat Message 2",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- @N8N/N8N Nodes Langchain.Chattrigger
- Code
- If
- Respondtowebhook
- Stickynote
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作